package com.study.leetcode;

//https://leetcode-cn.com/problems/rotate-image/
public class RotateImage {
    public void rotate(int[][] matrix) {
        if (matrix.length == 1) {
            return;
        }
        int temp;
        int len = matrix.length;
        //左下--右上 对角线翻转
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < len - i; j++) {
                temp = matrix[i][j];
                matrix[i][j] = matrix[len - j - 1][len - i - 1];
                matrix[len - j - 1][len - i - 1] = temp;
            }
        }
        //上下水平翻转
        for (int i = 0; i < len / 2; i++) {
            for (int j = 0; j < len; j++) {
                int tmp = matrix[i][j];
                matrix[i][j] = matrix[len - i - 1][j];
                matrix[len - i - 1][j] = tmp;
            }
        }
    }
}
